<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#b01").click(function () {
                var diqu = document.getElementById("tianqi").value;
                var urlstring = "http://apis.baidu.com/apistore/weatherservice/weather?citypinyin=" + diqu;
                htmlobj = $.ajax({
                    type: "GET",
                    url: urlstring,
                    dataType: "json", timeout: 3000, cache: true,
                    beforeSend: function (XMLHttpRequest) {
                        XMLHttpRequest.setRequestHeader("apikey", "94982a7d587e3d42d9d85e50d1dea51c");
                    },
                    success: function (data, msg) {
                        var json = eval(data);
                        var str = JSON.stringify(json);
                        alert(str);
                    }
                });
            });
        });
    </script>
</head>
<body>

<h2>百度天气查询API调用</h2>
<input type="text" name="tianqi" value="shanghai" id="tianqi"/>
<button id="b01" type="button">Change Content</button>

</body>
</html>